from multiprocessing import Process, Queue

items = ["leslie", "moon", "micheal", "hellen"]


def write_data(q: Queue):
    for i in range(5):
        print(f"{i} has been stored")
        q.put(i)
    print("write data is: ", i)


def read_data(q: Queue):
    while True:
        if q.empty():
            break
        item = q.get()
        # items.append(item)
        print(f"{item} has been read")


if __name__ == "__main__":
    q = Queue()  # 使用进程安全的队列
    p1 = Process(target=write_data, args=(q,))
    p2 = Process(target=read_data, args=(q,))

    p1.start()
    p1.join()
    # print(f"Q  size  is {q.qsize()} ")
    p2.start()
    p2.join()
    # print(f"Q  size  is {q.qsize()} ")
